<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>User Login</title>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<h2>User Login</h2>
<form id="loginForm">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username"><br><br>

    <label for="password">Password:</label>
    <input type="password" id="password" name="password"><br><br>

    <button type="submit">Login</button>
</form>

<p id="responseMessage"></p>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const form = document.getElementById('loginForm');
        if (!form) {
            console.error("Form not found!");
            return;
        }

        form.addEventListener('submit', function(event) {
            event.preventDefault();

            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;

            console.log("Username:", username);
            console.log("Password:", password);

            axios.post('/v1/login', {
                username: username,
                password: password
            })
                .then(function(response) {
                    document.getElementById('responseMessage').innerText = response.data;
                })
                .catch(function(error) {
                    document.getElementById('responseMessage').innerText = 'Error: ' + (error.response?.data || error.message);
                });
        });
    });
</script>

</body>
</html>
